package leetcode.code0243;

public class Solution {

	public int shortestDistance(String[] wordsDict, String word1, String word2) {
		int p1 = -1;
		int p2 = -1;
		int len = wordsDict.length;
		int ans = len;
		for (int i = 0; i < len; i++) {
			if (wordsDict[i].equals(word1)) {
				p1 = i;
				if (p2 != -1) {
					ans = Math.min(ans, p1 - p2);
				}
			} else if (wordsDict[i].equals(word2)) {
				p2 = i;
				if (p1 != -1) {
					ans = Math.min(ans, p2 - p1);
				}
			}
		}
		return ans;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
